package megrez.common.util;

import java.util.HashMap;
import java.util.Map;

import lombok.Getter;

/**
 * 基础运行异常
 *  
 * @author Lucky Yang
 * @since 0.0.1
 */
public class MegrezException extends RuntimeException {
    @Getter
    private ErrorCode errorCode;

    public MegrezException(ErrorCode errorCode) {
        super();
        this.errorCode = errorCode;
    }

    public MegrezException(ErrorCode errorCode, Throwable cause) {
        super(cause);
        this.errorCode = errorCode;
    }
    
    public Map<String, String> generateMap() {
        Map<String, String> rslt = new HashMap<>(3);
        rslt.put("code", errorCode.getCode());
        rslt.put("message", errorCode.getMessage());
        rslt.put("exception", this.getMessage());

        return rslt;
    }
}
